package com.LC.DAO;

import com.LC.Entity.Role;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleDAO {

    @Select("<script>"+
    "select * from t_role" +
    "<if test = 'value != null and value.length > 0'>" +
    "where keyword = #{value} or name = #{value}"+
    "</if>" +
    "</script>")
    public Page<Role> findPage(String queryString);
    
    @Insert("insert into t_role values(null,#{name},#{keyword},#{description})")
    @Options(useGeneratedKeys = true)
    public void addRole(Role addRole);
    
    @Insert("insert into t_role_permission values (#{roleId},#{permId})")
    public void addTot_role_permission(@Param("roleId") int roleId, @Param("permId") int permId);
    
    @Select("select * from t_role where id = #{id}")
    public Role getRoleById(int id);
    
    @Select("select permission_id from t_role_permission where role_id = #{id}")
    public List<Integer> getPermissionIdsByRoleId(int id);
    
    @Delete("delete from t_role_permission where role_id = #{id}")
    public void deleteT_role_permissionByRoleId(int id);
    
    @Update("update t_role set name = #{name}, keyword = #{keyword}, description = #{description} where id = #{id}")
    public void updateRole(Role updateRole);
    
    @Delete("delete from t_role where id = #{id}")
    public void deleteRole(int id);
    
    @Delete("delete from t_role_permission where role_id = #{id}")
    public void deleteFrom_t_role_permissionByRoleId(int id);
    
    @Select("select * from t_role")
    public List<Role> findAll();
}
